/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Control;

import DAO.PrivilegioDAO;
import DAO.ReservaDAO;
import DAO.UsuarioDAO;
import Model.Privilegio;
import Model.Reserva;
import Model.Usuario;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Gianfranco
 */
public class pesquisarReserva extends Processor{
    

    @Override
    public void execute() throws ServletException, IOException {
        HttpSession session = getRequest().getSession();
        
        String link = getRequest().getParameter("link");
        if(link == null){
            link = (String) session.getAttribute("link");
            if(link == null){
                throw new ServletException();
            }
        }
        session.setAttribute("link", link);      
                
        try{
            
            String login = getRequest().getParameter("loginPesquisa");
            if(login == null){
                login = (String) session.getAttribute("loginPesquisa");
                if(login == null){
                    throw new ServletException();
                }
            }
            session.setAttribute("idPesquisa", login);

            ArrayList<Reserva> reservas = new ArrayList<Reserva>();
            if(login.equals("")){
                reservas = ReservaDAO.Pesquisar();
            }
            
            
                getRequest().setAttribute("reservas", reservas);
                RequestDispatcher rd = getRequest().getRequestDispatcher(link);
                rd.forward(getRequest(), getResponse());
            
        }catch(SQLException e){
            throw new ServletException();
        }catch(ClassNotFoundException e){
            throw new ServletException();
        }
    }
    
}

